use serde::{Deserialize, Serialize};
use std::mem::ManuallyDrop;
use std::sync::RwLock;
use std::{
    collections::BTreeMap,
    sync::{Arc, Weak},
};
use time::OffsetDateTime;

mod plan_impl;
mod plan_set_impl;
mod tag;

#[derive(Debug)]
pub struct Plan {
    pub gid: ID,
    pub parent: Option<Weak<RwLock<Plan>>>,
    pub childs: BTreeMap<ID, Arc<RwLock<Plan>>>,
    pub title: String,
    pub description: String,
    pub tags: Vec<Tag>,
}

pub type ID = u64;
#[derive(Clone, Debug)]
pub struct PlanSet {
    pub set: ManuallyDrop<BTreeMap<ID, Arc<RwLock<Plan>>>>,
    pub root: ManuallyDrop<Arc<RwLock<Plan>>>,
    pub max_id: ID,
}
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)]
pub enum Tag {
    String(Arc<String>),
    Date(OffsetDateTime),
}
